package com.exonline.commons.utils;
/**
 * @desc   将url字符串截取的工具类
 * @author hbrj
 */

import java.net.URL;
import java.util.Arrays;
import java.util.List;

public class URLPathUtils {
    //
    public static String subUrl(String storerecordUrl) {
        try {
            // 解析 URL 并获取路径部分
            String path = new URL(storerecordUrl).getPath();

            // 使用 Stream API 和 Lambda 表达式提取文件名
            List<String> pathParts = Arrays.asList(path.split("/"));
            String fileName = pathParts.stream()
                    .filter(part -> !part.isEmpty())
                    .reduce((first, second) -> second)
                    .orElse("");

            // 获取截取的子路径
            System.out.println("Path: " + path.substring(1));
            System.out.println("File Name: " + fileName);
            return path.substring(1);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return storerecordUrl;
    }
}
